﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Net;
using System.Collections;
using System.Xml;
using System.Linq;
//using System.Xml.Linq;

using CommonUtils;
using TDAL = EzDAL.Auto2;
using TDALUtils = EzDAL.Utils;
using TConst = TERP.Constants;
using TUtils = TERP.Utils;
using TError = TERP.Errors;


namespace TERP.BizITS

{
    public partial class BizWater
	{
        #region //Validate

		#region //Hàng hóa
		#region //CheckExistMaHang
		private void CheckExistMaHang(
		   ref ArrayList alParamsCoupleError
		   , string strMaHang
		   , out DataTable dtCus
		)
		{
			dtCus = TDALUtils.DBUtils.GetTableContents(
				_dbCarSv // db
				, "Water_HangHoa" // strTableName
				, "top 1 *" // strColumnList
				, "" // strClauseOrderBy
				, "MaHang", "=", strMaHang // arrobjParamsTriple item
			 );

			if (dtCus == null || dtCus.Rows.Count == 0)
			{

				throw CMyException.Raise(
					TError.ErrITS.Its_HangHoaID_Not_Found
					, null
					, alParamsCoupleError.ToArray()
					);
			}
		}
		#endregion
		#endregion

        #endregion

        #region // Private Utils:
        #endregion

        #region // Public Ser_Mst_Location:
        public DataSet Ser_Mst_Location_Get(
		string strGWUserCode
		, string strGWPassword
		, string strTid
		, string strPartnerCode
		, string strPartnerUserCode
		, string strLanguageCode
		, string strLocationIDList
		, string strLocationCodeList
		, string strDealerCodeList
		, string strLocationNamePattern
		, string strLocationTypeList
		, string strIsActiveList
		)

		{

			#region // Temp:

			DataSet mdsFinal = CMyDataSet.NewMyDataSet(strTid);

			int nTidSeq = 0;

			bool bNeedTransaction = false;

			string strFunctionName = "Ser_Mst_Location_Get";

			string strErrorCodeDefault = "Ser_Mst_Location_Get";

			ArrayList alParamsCoupleError = new ArrayList(new object[]{

					"strFunctionName", strFunctionName
					, "strLocationIDList", strLocationIDList
					, "strLocationCodeList", strLocationCodeList
					, "strDealerCodeList", strDealerCodeList
					, "strLocationNamePattern", strLocationNamePattern
					, "strLocationTypeList", strLocationTypeList
					, "strIsActiveList", strIsActiveList
					});

			#endregion

			try
			{

				#region // Init:

				_dbCarSv.AppUserID = strPartnerUserCode;

				if (bNeedTransaction) _dbCarSv.BeginTransaction();

				// Write request log:

				_log.WriteLogAsync(

				_strConfig_GwUserCode // strGwUserCodeForLog

				, _strConfig_GwUserPasswordForLog // strGwPasswordForLog

				, strTid // strAppTid

				, strPartnerCode // strAppServiceCode

				, strPartnerUserCode // strAppUPartCode

				, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") // strAppTDateTime

				, TError.Error.NoError // strAppErrorCode

				, strFunctionName // strAppLogType1

				, "REQUEST" // strAppLogType2

				, "" // strAppLogType3

				, strLanguageCode // strAppLanguageCode

				, "" // strAppRemark

				, TUtils.CUtils.ParamsCouple2ParamsTriple(alParamsCoupleError, 1, "").ToArray() // arrobjParamsTriple

				);

				// Check Valid Tid:

				myUtils_ValidateId(

				ref alParamsCoupleError // alParamsCoupleError

				, strTid // strTid

				, TError.ErrITS.CommonInvalidTid // strErrCodeWhenInvalid

				);

				#endregion

				#region // Build Sql:

				ArrayList alParamsCoupleSql = new ArrayList();

				string strSqlGetData = @"
									select 
									t.*
									from Ser_Mst_Location t with (nolock)
									where (1=1)
									zzzzClauseWhereLocationIDList
									zzzzClauseWhereLocationCodeList
									zzzzClauseWhereDealerCodeList
									zzzzClauseWhereLocationNamePattern
									zzzzClauseWhereLocationTypeList
									zzzzClauseWhereIsActiveList
									;
				";

				string zzzzClauseWhereLocationIDList = SqlUtils.BuildClauseConditionList("and", "t.LocationID", strLocationIDList, "|");
				string zzzzClauseWhereLocationCodeList = SqlUtils.BuildClauseConditionList("and", "t.LocationCode", strLocationCodeList, "|");
				string zzzzClauseWhereDealerCodeList = SqlUtils.BuildClauseConditionList("and", "t.DealerCode", strDealerCodeList, "|");
				string zzzzClauseWhereLocationNamePattern = SqlUtils.BuildClauseConditionSingle("and", "t.LocationName", "like", "@strLocationNamePattern", strLocationNamePattern, ref alParamsCoupleSql);
				string zzzzClauseWhereLocationTypeList = SqlUtils.BuildClauseConditionList("and", "t.LocationType", strLocationTypeList, "|");
				string zzzzClauseWhereIsActiveList = SqlUtils.BuildClauseConditionList("and", "t.IsActive", strIsActiveList, "|");
				strSqlGetData = StringUtils.Replace(
				strSqlGetData
				, "zzzzClauseWhereLocationIDList", zzzzClauseWhereLocationIDList
				, "zzzzClauseWhereLocationCodeList", zzzzClauseWhereLocationCodeList
				, "zzzzClauseWhereDealerCodeList", zzzzClauseWhereDealerCodeList
				, "zzzzClauseWhereLocationNamePattern", zzzzClauseWhereLocationNamePattern
				, "zzzzClauseWhereLocationTypeList", zzzzClauseWhereLocationTypeList
				, "zzzzClauseWhereIsActiveList", zzzzClauseWhereIsActiveList
				);

				#endregion

				#region // Get Data:

				DataSet dsGetData = _dbCarSv.ExecQuery(

				strSqlGetData

				, alParamsCoupleSql.ToArray()

				);

				dsGetData.Tables[0].TableName = "Ser_Mst_Location";

				DataUtils.MoveDataTable(ref mdsFinal, ref dsGetData);

				#endregion

				// Return Good:

				TDALUtils.DBUtils.CommitSafety(_dbCarSv);

				mdsFinal.AcceptChanges();

				return mdsFinal;

			}

			catch (Exception exc)
			{

				#region // Catch of try:

				// Rollback:

				TDALUtils.DBUtils.RollbackSafety(_dbCarSv);

				// Return Bad:

				return TUtils.CProcessException.Process(

				ref mdsFinal

				, exc

				, strErrorCodeDefault
				, alParamsCoupleError.ToArray()

				);

				#endregion

			}

			finally
			{

				#region // Finally of try:

				// Rollback and Release resources:

				TDALUtils.DBUtils.RollbackSafety(_dbCarSv);

				TDALUtils.DBUtils.ReleaseAllSemaphore(_dbCarSv_Sys, true);

				TUtils.CProcessException.Process(

				ref mdsFinal // mdsFinal

				, _log // log

				, _strConfig_GwUserCode // strGwUserCodeForLog

				, _strConfig_GwUserPasswordForLog // strGwPasswordForLog

				, strFunctionName // strFunctionName

				, TUtils.CUtils.TidNext(strTid, ref nTidSeq) // strAppTid

				, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") // strAppTDateTime

				, strPartnerCode // strAppServiceCode

				, strPartnerUserCode // strAppUserCode

				, strLanguageCode // strLanguageCode

				, "" // strRemark"

				);

				#endregion

			}

		}
		public DataSet Ser_Mst_Location_Create(
		string strGWUserCode
		, string strGWPassword
		, string strTid
		, string strPartnerCode
		, string strPartnerUserCode
		, string strLanguageCode
		, string strLocationCode
		, string strDealerCode
		, string strLocationName
		, string strLocationType
		, string strLocationSurface
		, string strLocationHight
		)
		{
			#region // Temp:
			DataSet mdsFinal = CMyDataSet.NewMyDataSet(strTid);
			int nTidSeq = 0;
			bool bNeedTransaction = true;
			string strFunctionName = "Ser_Mst_Location_Create";
			string strErrorCodeDefault = "Ser_Mst_Location_Create";
			ArrayList alParamsCoupleError = new ArrayList(new object[]{
"strFunctionName", strFunctionName
, "strLocationCode", strLocationCode
, "strDealerCode", strDealerCode
, "strLocationName", strLocationName
, "strLocationType", strLocationType
, "strLocationSurface", strLocationSurface
, "strLocationHight", strLocationHight
});
			#endregion
			try
			{
				#region // Init:
				_dbCarSv.AppUserID = strPartnerUserCode;
				if (bNeedTransaction) _dbCarSv.BeginTransaction();
				// Write request log:
				_log.WriteLogAsync(
				_strConfig_GwUserCode // strGwUserCodeForLog
				, _strConfig_GwUserPasswordForLog // strGwPasswordForLog
				, strTid // strAppTid
				, strPartnerCode // strAppServiceCode
				, strPartnerUserCode // strAppUPartCode
				, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") // strAppTDateTime
				, TError.Error.NoError // strAppErrorCode
				, strFunctionName // strAppLogType1
				, "REQUEST" // strAppLogType2
				, "" // strAppLogType3
				, strLanguageCode // strAppLanguageCode
				, "" // strAppRemark
				, TUtils.CUtils.ParamsCouple2ParamsTriple(alParamsCoupleError, 1, "").ToArray() // arrobjParamsTriple
				);
				// Check Valid Tid:
				myUtils_ValidateId(
				ref alParamsCoupleError // alParamsCoupleError
				, strTid // strTid
				, TError.ErrITS.CommonInvalidTid // strErrCodeWhenInvalid
				);
				#endregion

				#region // Check:
				#endregion

				#region // dt_MST_Location:
				DataTable dt_MST_Location = TDALUtils.DBUtils.GetSchema(_dbCarSv, "Ser_MST_Location").Tables[0];
				dt_MST_Location.Rows.Add(dt_MST_Location.NewRow());
				dt_MST_Location.Rows[0]["LocationCode"] = strLocationCode;
				dt_MST_Location.Rows[0]["DealerCode"] = strDealerCode;
				dt_MST_Location.Rows[0]["LocationName"] = strLocationName;
				dt_MST_Location.Rows[0]["LocationType"] = strLocationType;
				dt_MST_Location.Rows[0]["LocationSurface"] = strLocationSurface;
				dt_MST_Location.Rows[0]["LocationHight"] = strLocationHight;
				dt_MST_Location.Rows[0]["IsActive"] = 1;
				_dbCarSv.SaveData("Ser_MST_Location", dt_MST_Location);
				#endregion
				#region // Return data
				//Get ID
				string strSqlGetID = @"
									declare @ID int

									select @ID = @@Identity
									
									select l.* 
									from Ser_MST_Location l
									where (1=1)
										and l.LocationID = @ID
									;";

				//Return data
				DataSet dsGetData = _dbCarSv.ExecQuery(

								strSqlGetID

								);

				dsGetData.Tables[0].TableName = "Ser_Mst_Location";

				DataUtils.MoveDataTable(ref mdsFinal, ref dsGetData);

				#endregion

				// Return Good:
				TDALUtils.DBUtils.CommitSafety(_dbCarSv);
				mdsFinal.AcceptChanges();
				return mdsFinal;
			}
			catch (Exception exc)
			{
				#region // Catch of try:
				// Rollback:
				TDALUtils.DBUtils.RollbackSafety(_dbCarSv);
				// Return Bad:
				return TUtils.CProcessException.Process(
				ref mdsFinal
				, exc
				, strErrorCodeDefault
				, alParamsCoupleError.ToArray()
				);
				#endregion
			}
			finally
			{
				#region // Finally of try:
				// Rollback and Release resources:
				TDALUtils.DBUtils.RollbackSafety(_dbCarSv);
				TDALUtils.DBUtils.ReleaseAllSemaphore(_dbCarSv_Sys, true);
				TUtils.CProcessException.Process(
				ref mdsFinal // mdsFinal
				, _log // log
				, _strConfig_GwUserCode // strGwUserCodeForLog
				, _strConfig_GwUserPasswordForLog // strGwPasswordForLog
				, strFunctionName // strFunctionName
				, TUtils.CUtils.TidNext(strTid, ref nTidSeq) // strAppTid
				, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") // strAppTDateTime
				, strPartnerCode // strAppServiceCode
				, strPartnerUserCode // strAppUserCode
				, strLanguageCode // strLanguageCode
				, " // strRemark"
				);
				#endregion
			}
		}

		public DataSet Ser_Mst_Location_Delete(
		string strGWUserCode
		, string strGWPassword
		, string strTid
		, string strPartnerCode
		, string strPartnerUserCode
		, string strLanguageCode
		, string strLocationID
		)
		{
			#region // Temp:
			DataSet mdsFinal = CMyDataSet.NewMyDataSet(strTid);
			int nTidSeq = 0;
			bool bNeedTransaction = false;
			string strFunctionName = "Ser_Mst_Location_Delete";
			string strErrorCodeDefault = "TError.ErrITS.Ser_Mst_Location_Delete";
			ArrayList alParamsCoupleError = new ArrayList(new object[]{
		"strFunctionName", strFunctionName
		, "strLocationID", strLocationID
		});
			#endregion

			try
			{
				#region // Init:
				_dbCarSv.AppUserID = strPartnerUserCode;
				if (bNeedTransaction) _dbCarSv.BeginTransaction();

				// Write request log:
				_log.WriteLogAsync(
				_strConfig_GwUserCode // strGwUserCodeForLog
				, _strConfig_GwUserPasswordForLog // strGwPasswordForLog
				, strTid // strAppTid
				, strPartnerCode // strAppServiceCode
				, strPartnerUserCode // strAppUPartCode
				, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") // strAppTDateTime
				, TError.Error.NoError // strAppErrorCode
				, strFunctionName // strAppLogType1
				, "REQUEST" // strAppLogType2
				, "" // strAppLogType3
				, strLanguageCode // strAppLanguageCode
				, "" // strAppRemark
				, TUtils.CUtils.ParamsCouple2ParamsTriple(alParamsCoupleError, 1, "").ToArray() // arrobjParamsTriple
				);

				// Check Valid Tid:
				myUtils_ValidateId(
				ref alParamsCoupleError // alParamsCoupleError
				, strTid // strTid
				, TError.ErrITS.CommonInvalidTid // strErrCodeWhenInvalid
				);
				#endregion

				#region // Delete:

				// Init:
				string strSqlDelete = @"
						update Ser_MST_Location
						set IsActive = 0
						where
							LocationID = @LocationID
						;
					";

				// Save:
				_dbCarSv.ExecQuery(
					strSqlDelete
					, "@LocationID", strLocationID
					);

				#endregion

				// Return Good:
				TDALUtils.DBUtils.CommitSafety(_dbCarSv);
				mdsFinal.AcceptChanges();
				return mdsFinal;
			}
			catch (Exception exc)
			{
				#region // Catch of try:
				// Rollback:
				TDALUtils.DBUtils.RollbackSafety(_dbCarSv);

				strErrorCodeDefault = TUtils.DProcessException.ProcessException(exc, strErrorCodeDefault);

				// Return Bad:
				return TUtils.CProcessException.Process(
				ref mdsFinal
				, exc
				, strErrorCodeDefault
				, alParamsCoupleError.ToArray()
				);
				#endregion
			}
			finally
			{
				#region // Finally of try:
				// Rollback and Release resources:
				TDALUtils.DBUtils.RollbackSafety(_dbCarSv);
				TDALUtils.DBUtils.ReleaseAllSemaphore(_dbCarSv_Sys, true);

				TUtils.CProcessException.Process(
				ref mdsFinal // mdsFinal
				, _log // log
				, _strConfig_GwUserCode // strGwUserCodeForLog
				, _strConfig_GwUserPasswordForLog // strGwPasswordForLog
				, strFunctionName // strFunctionName
				, TUtils.CUtils.TidNext(strTid, ref nTidSeq) // strAppTid
				, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") // strAppTDateTime
				, strPartnerCode // strAppServiceCode
				, strPartnerUserCode // strAppUPartCode
				, strLanguageCode // strLanguageCode
				, "" // strRemark
				);
				#endregion
			}
		}

		public DataSet Ser_Mst_Location_Update(

		string strGWUserCode

		, string strGWPassword

		, string strTid

		, string strPartnerCode

		, string strPartnerUserCode

		, string strLanguageCode

		, string strLocationID
		, string strLocationCode
		, string strDealerCode
		, string strLocationName
		, string strLocationType
		, string strLocationSurface
		, string strLocationHight

		)
		{

			#region // Temp:

			DataSet mdsFinal = CMyDataSet.NewMyDataSet(strTid);

			int nTidSeq = 0;

			bool bNeedTransaction = false;

			string strFunctionName = "Ser_Mst_Location_Update";

			string strErrorCodeDefault = "TError.ErrITS.Ser_Mst_Location_Update";

			ArrayList alParamsCoupleError = new ArrayList(new object[]{

"strFunctionName", strFunctionName
, "strLocationID", strLocationID
, "strLocationCode", strLocationCode
, "strDealerCode", strDealerCode
, "strLocationName", strLocationName
, "strLocationType", strLocationType
, "strLocationSurface", strLocationSurface
, "strLocationHight", strLocationHight
});

			#endregion

			try
			{

				#region // Init:

				_dbCarSv.AppUserID = strPartnerUserCode;

				if (bNeedTransaction) _dbCarSv.BeginTransaction();

				// Write request log:

				_log.WriteLogAsync(

				_strConfig_GwUserCode // strGwUserCodeForLog

				, _strConfig_GwUserPasswordForLog // strGwPasswordForLog

				, strTid // strAppTid

				, strPartnerCode // strAppServiceCode

				, strPartnerUserCode // strAppUPartCode

				, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") // strAppTDateTime

				, TError.Error.NoError // strAppErrorCode

				, strFunctionName // strAppLogType1

				, "REQUEST" // strAppLogType2

				, "" // strAppLogType3

				, strLanguageCode // strAppLanguageCode

				, "" // strAppRemark

				, TUtils.CUtils.ParamsCouple2ParamsTriple(alParamsCoupleError, 1, "").ToArray() // arrobjParamsTriple

				);

				// Check Valid Tid:

				myUtils_ValidateId(

				ref alParamsCoupleError // alParamsCoupleError

				, strTid // strTid

				, TError.ErrITS.CommonInvalidTid // strErrCodeWhenInvalid

				);

				#endregion

				#region // Update:

				ArrayList alEffectiveColumn = new ArrayList();

				DataTable dt_MST_Location = TDALUtils.DBUtils.GetTableContents(

				_dbCarSv // db

				, "Ser_MST_Location" // strTableName

				, "top 1 *"

				, ""

				, "LocationID", "=", strLocationID

				);

				dt_MST_Location.Rows[0]["LocationCode"] = strLocationCode; alEffectiveColumn.Add("LocationCode");
				dt_MST_Location.Rows[0]["DealerCode"] = strDealerCode; alEffectiveColumn.Add("DealerCode");
				dt_MST_Location.Rows[0]["LocationName"] = strLocationName; alEffectiveColumn.Add("LocationName");
				dt_MST_Location.Rows[0]["LocationType"] = strLocationType; alEffectiveColumn.Add("LocationType");
				dt_MST_Location.Rows[0]["LocationSurface"] = strLocationSurface; alEffectiveColumn.Add("LocationSurface");
				dt_MST_Location.Rows[0]["LocationHight"] = strLocationHight; alEffectiveColumn.Add("LocationHight");
				_dbCarSv.SaveData("Ser_MST_Location", dt_MST_Location, alEffectiveColumn.ToArray());

				#endregion

				// Return Good:

				TDALUtils.DBUtils.CommitSafety(_dbCarSv);

				mdsFinal.AcceptChanges();

				return mdsFinal;

			}

			catch (Exception exc)
			{

				#region // Catch of try:

				// Rollback:

				TDALUtils.DBUtils.RollbackSafety(_dbCarSv);

				// Return Bad:

				return TUtils.CProcessException.Process(

				ref mdsFinal

				, exc

				, strErrorCodeDefault
				, alParamsCoupleError.ToArray()

				);

				#endregion

			}

			finally
			{

				#region // Finally of try:

				// Rollback and Release resources:

				TDALUtils.DBUtils.RollbackSafety(_dbCarSv);

				TDALUtils.DBUtils.ReleaseAllSemaphore(_dbCarSv_Sys, true);

				TUtils.CProcessException.Process(

				ref mdsFinal // mdsFinal

				, _log // log

				, _strConfig_GwUserCode // strGwUserCodeForLog

				, _strConfig_GwUserPasswordForLog // strGwPasswordForLog

				, strFunctionName // strFunctionName

				, TUtils.CUtils.TidNext(strTid, ref nTidSeq) // strAppTid

				, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") // strAppTDateTime

				, strPartnerCode // strAppServiceCode

				, strPartnerUserCode // strAppUPartCode

				, strLanguageCode // strLanguageCode

				, "" // strRemark

				);

				#endregion

			}

		}

		#endregion

        #region Office
        public DataSet Its_Office_Get(
        string strGWUserCode
        , string strGWPassword
        , string strTid
        , string strPartnerCode
        , string strPartnerUserCode
        , string strLanguageCode
        , string strOfficeCodeList
        , string strOfficeNamePattern
        , string strOfficceAddressPattern
        )
        {

            #region // Temp:

            DataSet mdsFinal = CMyDataSet.NewMyDataSet(strTid);

            int nTidSeq = 0;

            bool bNeedTransaction = false;

            string strFunctionName = "Its_Office_Get";

            string strErrorCodeDefault = "TError.ErrITS.Ser_Mst_Location_Get";

            ArrayList alParamsCoupleError = new ArrayList(new object[]{

					"strFunctionName", strFunctionName
					, "strOfficeCodeList", strOfficeCodeList
					, "strOfficeNamePattern", strOfficeNamePattern
					, "strOfficceAddressPattern", strOfficceAddressPattern
					});

            #endregion

            try
            {

                #region // Init:

                _dbCarSv.AppUserID = strPartnerUserCode;

                if (bNeedTransaction) _dbCarSv.BeginTransaction();

                // Write request log:

                _log.WriteLogAsync(

                _strConfig_GwUserCode // strGwUserCodeForLog

                , _strConfig_GwUserPasswordForLog // strGwPasswordForLog

                , strTid // strAppTid

                , strPartnerCode // strAppServiceCode

                , strPartnerUserCode // strAppUPartCode

                , DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") // strAppTDateTime

                , TError.Error.NoError // strAppErrorCode

                , strFunctionName // strAppLogType1

                , "REQUEST" // strAppLogType2

                , "" // strAppLogType3

                , strLanguageCode // strAppLanguageCode

                , "" // strAppRemark

                , TUtils.CUtils.ParamsCouple2ParamsTriple(alParamsCoupleError, 1, "").ToArray() // arrobjParamsTriple

                );

                // Check Valid Tid:

                myUtils_ValidateId(

                ref alParamsCoupleError // alParamsCoupleError

                , strTid // strTid

                , TError.ErrITS.CommonInvalidTid // strErrCodeWhenInvalid

                );

                #endregion

                #region // Build Sql:

                ArrayList alParamsCoupleSql = new ArrayList();

                string strSqlGetData = @"
									select 
									t.*
									from Offices t with (nolock)
									where (1=1)
									zzzzClauseWhereOfficeCodeList									
									zzzzClauseWhereOfficeNamePattern
									zzzzClauseWhereOfficeAddressPattern								
									;
				";

                string zzzzClauseWhereOfficeCodeList = SqlUtils.BuildClauseConditionList("and", "t.OfficeCode", strOfficeCodeList, "|");

                string zzzzClauseWhereOfficeNamePattern = SqlUtils.BuildClauseConditionSingle("and", "t.OfficeName", "like", "@p", strOfficeNamePattern, ref alParamsCoupleSql);
                string zzzzClauseWhereOfficeAddressPattern = SqlUtils.BuildClauseConditionSingle("and", "t.OfficeAddress", "like", "@p", strOfficceAddressPattern, ref alParamsCoupleSql);
                strSqlGetData = StringUtils.Replace(
                strSqlGetData
                , "zzzzClauseWhereOfficeCodeList", zzzzClauseWhereOfficeCodeList
                , "zzzzClauseWhereOfficeNamePattern", zzzzClauseWhereOfficeNamePattern
                , "zzzzClauseWhereOfficeAddressPattern", zzzzClauseWhereOfficeAddressPattern
                );

                #endregion

                #region // Get Data:

                DataSet dsGetData = _dbCarSv.ExecQuery(

                strSqlGetData

                , alParamsCoupleSql.ToArray()

                );

                dsGetData.Tables[0].TableName = "Offices";

                DataUtils.MoveDataTable(ref mdsFinal, ref dsGetData);

                #endregion

                // Return Good:

                TDALUtils.DBUtils.CommitSafety(_dbCarSv);

                mdsFinal.AcceptChanges();

                return mdsFinal;

            }

            catch (Exception exc)
            {

                #region // Catch of try:

                // Rollback:

                TDALUtils.DBUtils.RollbackSafety(_dbCarSv);

                // Return Bad:

                return TUtils.CProcessException.Process(

                ref mdsFinal

                , exc

                , strErrorCodeDefault
                , alParamsCoupleError.ToArray()

                );

                #endregion

            }

            finally
            {

                #region // Finally of try:

                // Rollback and Release resources:

                TDALUtils.DBUtils.RollbackSafety(_dbCarSv);

                TDALUtils.DBUtils.ReleaseAllSemaphore(_dbCarSv_Sys, true);

                TUtils.CProcessException.Process(

                ref mdsFinal // mdsFinal

                , _log // log

                , _strConfig_GwUserCode // strGwUserCodeForLog

                , _strConfig_GwUserPasswordForLog // strGwPasswordForLog

                , strFunctionName // strFunctionName

                , TUtils.CUtils.TidNext(strTid, ref nTidSeq) // strAppTid

                , DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") // strAppTDateTime

                , strPartnerCode // strAppServiceCode

                , strPartnerUserCode // strAppUserCode

                , strLanguageCode // strLanguageCode

                , "" // strRemark"

                );

                #endregion

            }

        }

        public DataSet Its_Office_Create(
        string strGWUserCode
        , string strGWPassword
        , string strTid
        , string strPartnerCode
        , string strPartnerUserCode
        , string strLanguageCode
        , string strOfficeCode
        , string strOfficeName
        , string strAddress
        , string strTel
        , string strMobile
        , string strFax
        , string strEmail
        , string strWebsite
        , string strNote
        )
        {
            #region // Temp:
            DataSet mdsFinal = CMyDataSet.NewMyDataSet(strTid);
            int nTidSeq = 0;
            bool bNeedTransaction = true;
            string strFunctionName = "Its_Office_Create";
            string strErrorCodeDefault = TError.ErrITS.Its_Office_Create;
            ArrayList alParamsCoupleError = new ArrayList(new object[]{
"strFunctionName", strFunctionName
, "strOfficeCode", strOfficeCode
, "strOfficeName", strOfficeName
, "strAddress", strAddress
, "strTel", strTel
, "strMobile", strMobile
, "strFax", strFax
, "strEmail",strEmail
, "strWebsite",strWebsite
, "strNote",strNote
});
            #endregion
            try
            {
                #region // Init:
                _dbCarSv.AppUserID = strPartnerUserCode;
                if (bNeedTransaction) _dbCarSv.BeginTransaction();
                // Write request log:
                _log.WriteLogAsync(
                _strConfig_GwUserCode // strGwUserCodeForLog
                , _strConfig_GwUserPasswordForLog // strGwPasswordForLog
                , strTid // strAppTid
                , strPartnerCode // strAppServiceCode
                , strPartnerUserCode // strAppUPartCode
                , DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") // strAppTDateTime
                , TError.Error.NoError // strAppErrorCode
                , strFunctionName // strAppLogType1
                , "REQUEST" // strAppLogType2
                , "" // strAppLogType3
                , strLanguageCode // strAppLanguageCode
                , "" // strAppRemark
                , TUtils.CUtils.ParamsCouple2ParamsTriple(alParamsCoupleError, 1, "").ToArray() // arrobjParamsTriple
                );
                // Check Valid Tid:
                myUtils_ValidateId(
                ref alParamsCoupleError // alParamsCoupleError
                , strTid // strTid
                , TError.ErrITS.CommonInvalidTid // strErrCodeWhenInvalid
                );
                #endregion

                #region // Check:
                #endregion

                #region // dt_Office:
                DataTable dt_Office = TDALUtils.DBUtils.GetSchema(_dbCarSv, "Offices").Tables[0];
                dt_Office.Rows.Add(dt_Office.NewRow());
                dt_Office.Rows[0]["OfficeCode"] = strOfficeCode;
                dt_Office.Rows[0]["OfficeName"] = strOfficeName;
                dt_Office.Rows[0]["Address"] = strAddress;
                dt_Office.Rows[0]["Tel"] = strTel;
                dt_Office.Rows[0]["Mobile"] = strMobile;
                dt_Office.Rows[0]["Fax"] = strFax;
                dt_Office.Rows[0]["Email"] = strEmail;
                dt_Office.Rows[0]["Website"] = strWebsite;
                dt_Office.Rows[0]["Note"] = strNote;

                //Save
                _dbCarSv.SaveData("Offices", dt_Office);
                #endregion
                #region // Return data
                //Get ID
                string strSqlGetID = @"									
									select o.* 
									from Offices o
									where (1=1)
										and o.OfficeCode = '"+strOfficeCode+"';";

                //Return data
                DataSet dsGetData = _dbCarSv.ExecQuery(

                                strSqlGetID

                                );

                dsGetData.Tables[0].TableName = "Offices";

                DataUtils.MoveDataTable(ref mdsFinal, ref dsGetData);

                #endregion

                // Return Good:
                TDALUtils.DBUtils.CommitSafety(_dbCarSv);
                mdsFinal.AcceptChanges();
                return mdsFinal;
            }
            catch (Exception exc)
            {
                #region // Catch of try:
                // Rollback:
                TDALUtils.DBUtils.RollbackSafety(_dbCarSv);
                // Return Bad:
                return TUtils.CProcessException.Process(
                ref mdsFinal
                , exc
                , strErrorCodeDefault
                , alParamsCoupleError.ToArray()
                );
                #endregion
            }
            finally
            {
                #region // Finally of try:
                // Rollback and Release resources:
                TDALUtils.DBUtils.RollbackSafety(_dbCarSv);
                TDALUtils.DBUtils.ReleaseAllSemaphore(_dbCarSv_Sys, true);
                TUtils.CProcessException.Process(
                ref mdsFinal // mdsFinal
                , _log // log
                , _strConfig_GwUserCode // strGwUserCodeForLog
                , _strConfig_GwUserPasswordForLog // strGwPasswordForLog
                , strFunctionName // strFunctionName
                , TUtils.CUtils.TidNext(strTid, ref nTidSeq) // strAppTid
                , DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") // strAppTDateTime
                , strPartnerCode // strAppServiceCode
                , strPartnerUserCode // strAppUserCode
                , strLanguageCode // strLanguageCode
                , " // strRemark"
                );
                #endregion
            }
        }
        #endregion Office

	

		#region //Hàng hóa

		#region Its_WaterHangHoa_Get
		public DataSet Its_WaterHangHoa_Get(
		string strGWUserCode
		, string strGWPassword
		, string strTid
		, string strPartnerCode
		, string strPartnerUserCode
		, string strLanguageCode
		, string strMahangConditionList
		, string strTenhangConditionList
		)
		{

			#region // Temp:

			DataSet mdsFinal = CMyDataSet.NewMyDataSet(strTid);

			int nTidSeq = 0;
			bool bNeedTransaction = false;
			string strFunctionName = "Its_HangHoa_Get";
			string strErrorCodeDefault = TError.ErrITS.Its_HangHoa_Get;
			ArrayList alParamsCoupleError = new ArrayList(new object[]{

					"strFunctionName", strFunctionName
                    , "strMahangConditionList", strMahangConditionList
					, "strTenhangConditionList", strTenhangConditionList
					});

			#endregion

			try
			{

				#region // Init:

				_dbCarSv.AppUserID = strPartnerUserCode;

				if (bNeedTransaction) _dbCarSv.BeginTransaction();

				// Write request log:

				_log.WriteLogAsync(

				_strConfig_GwUserCode // strGwUserCodeForLog

				, _strConfig_GwUserPasswordForLog // strGwPasswordForLog

				, strTid // strAppTid

				, strPartnerCode // strAppServiceCode

				, strPartnerUserCode // strAppUPartCode

				, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") // strAppTDateTime

				, TError.Error.NoError // strAppErrorCode

				, strFunctionName // strAppLogType1

				, "REQUEST" // strAppLogType2

				, "" // strAppLogType3

				, strLanguageCode // strAppLanguageCode

				, "" // strAppRemark

				, TUtils.CUtils.ParamsCouple2ParamsTriple(alParamsCoupleError, 1, "").ToArray() // arrobjParamsTriple

				);

				// Check Valid Tid:

				myUtils_ValidateId(

				ref alParamsCoupleError // alParamsCoupleError

				, strTid // strTid

				, TError.ErrITS.CommonInvalidTid // strErrCodeWhenInvalid

				);

				#endregion

				#region // Build Sql:

				ArrayList alParamsCoupleSql = new ArrayList();

				string strSqlGetData = @"
						SELECT
                               t.*
                        FROM Water_HangHoa t with (nolock)
						WHERE (1=1)
                                    zzzzClauseWhereMahangConditionList
                                    zzzzClauseWhereTenhangConditionList
									;
				";

				string zzzzClauseWhereMahangConditionList = SqlUtils.BuildClause("and", "t.Mahang", strMahangConditionList, "@p", ref alParamsCoupleSql);
				string zzzzClauseWhereTenhangConditionList = SqlUtils.BuildClause("and", "t.Tenhang", strTenhangConditionList, "@p", ref alParamsCoupleSql);
				;

				strSqlGetData = StringUtils.Replace(
				strSqlGetData
				, "zzzzClauseWhereMahangConditionList", zzzzClauseWhereMahangConditionList
				, "zzzzClauseWhereTenhangConditionList", zzzzClauseWhereTenhangConditionList
				);

				#endregion

				#region // Get Data:
				myDebug_SaveSql(
					_bDebugMode // bDebugMode
					, ref alParamsCoupleError // alParamsCoupleError
					, string.Format("strSql_{0}", strFunctionName) // strParamName
					, strSqlGetData // strSql
					);


				DataSet dsGetData = _dbCarSv.ExecQuery(

				strSqlGetData

				, alParamsCoupleSql.ToArray()

				);

				dsGetData.Tables[0].TableName = "Water_HangHoa";

				DataUtils.MoveDataTable(ref mdsFinal, ref dsGetData);

				#endregion

				// Return Good:

				TDALUtils.DBUtils.CommitSafety(_dbCarSv);

				mdsFinal.AcceptChanges();

				return mdsFinal;

			}

			catch (Exception exc)
			{

				#region // Catch of try:

				// Rollback:

				TDALUtils.DBUtils.RollbackSafety(_dbCarSv);

				// Return Bad:

				return TUtils.CProcessException.Process(

				ref mdsFinal

				, exc

				, strErrorCodeDefault
				, alParamsCoupleError.ToArray()

				);

				#endregion

			}

			finally
			{

				#region // Finally of try:

				// Rollback and Release resources:

				TDALUtils.DBUtils.RollbackSafety(_dbCarSv);

				TDALUtils.DBUtils.ReleaseAllSemaphore(_dbCarSv_Sys, true);

				TUtils.CProcessException.Process(

				ref mdsFinal // mdsFinal

				, _log // log

				, _strConfig_GwUserCode // strGwUserCodeForLog

				, _strConfig_GwUserPasswordForLog // strGwPasswordForLog

				, strFunctionName // strFunctionName

				, TUtils.CUtils.TidNext(strTid, ref nTidSeq) // strAppTid

				, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") // strAppTDateTime

				, strPartnerCode // strAppServiceCode

				, strPartnerUserCode // strAppUserCode

				, strLanguageCode // strLanguageCode

				, "" // strRemark"

				);

				#endregion

			}

		}

		#endregion

		#region //Its_Water_HangHoa_Create
		public DataSet Its_Water_HangHoa_Create(
			 string strGWUserCode
			 , string strGWPassword
			 , string strTid
			 , string strPartnerCode
			 , string strPartnerUserCode
			 , string strLanguageCode
			 , string strMahang
			 , string strTenHang
			 , string strQuantity
			 , string strUnit
			 , string strPrice
			 , string strCost
			 , string strNote
	 )
		{
			#region // Temp:
			DataSet mdsFinal = CMyDataSet.NewMyDataSet(strTid);
			int nTidSeq = 0;
			bool bNeedTransaction = true;
			string strFunctionName = "Its_HangHoa_Create";
			string strErrorCodeDefault = TError.ErrITS.Its_HangHoa_Create;
			ArrayList alParamsCoupleError = new ArrayList(new object[]{
			"strFunctionName", strFunctionName
			, "strMahang", strMahang
			, "strTenHang", strTenHang
			, "strQuantity", strQuantity
			, "strUnit", strUnit
			, "strPrice",strPrice
			, "strCost",strCost
			, "strNote", strNote
			});
			#endregion
			try
			{
				#region // Init:
				_dbCarSv.AppUserID = strPartnerUserCode;
				if (bNeedTransaction) _dbCarSv.BeginTransaction();
				// Write request log:
				_log.WriteLogAsync(
				_strConfig_GwUserCode // strGwUserCodeForLog
				, _strConfig_GwUserPasswordForLog // strGwPasswordForLog
				, strTid // strAppTid
				, strPartnerCode // strAppServiceCode
				, strPartnerUserCode // strAppUPartCode
				, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") // strAppTDateTime
				, TError.Error.NoError // strAppErrorCode
				, strFunctionName // strAppLogType1
				, "REQUEST" // strAppLogType2
				, "" // strAppLogType3
				, strLanguageCode // strAppLanguageCode
				, "" // strAppRemark
				, TUtils.CUtils.ParamsCouple2ParamsTriple(alParamsCoupleError, 1, "").ToArray() // arrobjParamsTriple
				);
				// Check Valid Tid:
				myUtils_ValidateId(
				ref alParamsCoupleError // alParamsCoupleError
				, strTid // strTid
				, TError.ErrITS.CommonInvalidTid // strErrCodeWhenInvalid
				);
				#endregion

				#region // Check:

				//if (dsBookGuideDetail == null || dsBookGuideDetail.Tables.Count == 0)
				//{
				//    throw CMyException.Raise(
				//   TError.ErrITS.Its_BookingTour_NotFoundDetail
				//   , null
				//   , alParamsCoupleError.ToArray()
				//   );
				//}
				//else
				//{
				//    if (dsBookGuideDetail.Tables["BookGuideDetail"].Rows.Count == 0)
				//    {
				//        throw CMyException.Raise(
				//    TError.ErrITS.Its_BookGuide_NotFoundDetail
				//    , null
				//    , alParamsCoupleError.ToArray()
				//  );
				//    }
				//}
				#endregion

				#region // dt_Book:
				DataTable dt_Book = TDALUtils.DBUtils.GetSchema(_dbCarSv, "Water_HangHoa").Tables[0];
				dt_Book.Rows.Add(dt_Book.NewRow());
				dt_Book.Rows[0]["Mahang"] = strMahang;
				if (!StringUtils.IsEmpty(strTenHang))
				{
					dt_Book.Rows[0]["TenHang"] = strTenHang;
				}

				if (!StringUtils.IsEmpty(strQuantity))
				{
					dt_Book.Rows[0]["Quantity"] = strQuantity;
				}

				if (!StringUtils.IsEmpty(strUnit))
				{
					dt_Book.Rows[0]["Unit"] = strUnit;
				}

				if (!StringUtils.IsEmpty(strPrice))
				{
					dt_Book.Rows[0]["Price"] = strPrice;
				}
				if (!StringUtils.IsEmpty(strCost))
				{
					dt_Book.Rows[0]["Cost"] = strCost;
				}

				if (!StringUtils.IsEmpty(strNote))
				{
					dt_Book.Rows[0]["NOTE"] = strNote;
				}

				//Save
				_dbCarSv.SaveData("Water_HangHoa", dt_Book);
				
				#endregion

				#region // Return data

				DataSet dsGetData = new DataSet();
				dsGetData.Tables.Add(dt_Book.Copy());
				dsGetData.Tables[0].TableName = "Water_HangHoa";

				DataUtils.MoveDataTable(ref mdsFinal, ref dsGetData);

				#endregion

				// Return Good:
				TDALUtils.DBUtils.CommitSafety(_dbCarSv);
				mdsFinal.AcceptChanges();
				return mdsFinal;
			}
			catch (Exception exc)
			{
				#region // Catch of try:
				// Rollback:
				TDALUtils.DBUtils.RollbackSafety(_dbCarSv);
				// Return Bad:
				return TUtils.CProcessException.Process(
				ref mdsFinal
				, exc
				, strErrorCodeDefault
				, alParamsCoupleError.ToArray()
				);
				#endregion
			}
			finally
			{
				#region // Finally of try:
				// Rollback and Release resources:
				TDALUtils.DBUtils.RollbackSafety(_dbCarSv);
				TDALUtils.DBUtils.ReleaseAllSemaphore(_dbCarSv_Sys, true);
				TUtils.CProcessException.Process(
				ref mdsFinal // mdsFinal
				, _log // log
				, _strConfig_GwUserCode // strGwUserCodeForLog
				, _strConfig_GwUserPasswordForLog // strGwPasswordForLog
				, strFunctionName // strFunctionName
				, TUtils.CUtils.TidNext(strTid, ref nTidSeq) // strAppTid
				, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") // strAppTDateTime
				, strPartnerCode // strAppServiceCode
				, strPartnerUserCode // strAppUserCode
				, strLanguageCode // strLanguageCode
				, " // strRemark"
				);
				#endregion
			}
		}

		#endregion

		#region //Its_Water_HangHoa_Update
		public DataSet Its_Water_HangHoa_Update(
			 string strGWUserCode
			 , string strGWPassword
			 , string strTid
			 , string strPartnerCode
			 , string strPartnerUserCode
			 , string strLanguageCode
			 , string strMahang
			 , string strTenHang
			 , string strQuantity
			 , string strUnit
			 , string strPrice
			 , string strCost
			 , string strNote
	 )
		{
			#region // Temp:
			DataSet mdsFinal = CMyDataSet.NewMyDataSet(strTid);
			int nTidSeq = 0;
			bool bNeedTransaction = true;
			string strFunctionName = "Its_Water_HangHoa_Update";
			string strErrorCodeDefault = TError.ErrITS.Its_HangHoa_Update;
			ArrayList alParamsCoupleError = new ArrayList(new object[]{
			"strFunctionName", strFunctionName
			, "strMahang", strMahang
			, "strTenHang", strTenHang
			, "strQuantity", strQuantity
			, "strUnit", strUnit
			, "strPrice",strPrice
			, "strCost",strCost
			, "strNote", strNote
			});
			#endregion
			try
			{
				#region // Init:
				_dbCarSv.AppUserID = strPartnerUserCode;
				if (bNeedTransaction) _dbCarSv.BeginTransaction();
				// Write request log:
				_log.WriteLogAsync(
				_strConfig_GwUserCode // strGwUserCodeForLog
				, _strConfig_GwUserPasswordForLog // strGwPasswordForLog
				, strTid // strAppTid
				, strPartnerCode // strAppServiceCode
				, strPartnerUserCode // strAppUPartCode
				, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") // strAppTDateTime
				, TError.Error.NoError // strAppErrorCode
				, strFunctionName // strAppLogType1
				, "REQUEST" // strAppLogType2
				, "" // strAppLogType3
				, strLanguageCode // strAppLanguageCode
				, "" // strAppRemark
				, TUtils.CUtils.ParamsCouple2ParamsTriple(alParamsCoupleError, 1, "").ToArray() // arrobjParamsTriple
				);
				// Check Valid Tid:
				myUtils_ValidateId(
				ref alParamsCoupleError // alParamsCoupleError
				, strTid // strTid
				, TError.ErrITS.CommonInvalidTid // strErrCodeWhenInvalid
				);
				#endregion

				#region // Check:

				DataTable dt_Book = null;
				CheckExistMaHang(ref alParamsCoupleError
								, strMahang
								, out dt_Book);
				#endregion

				#region // dt_Book:

				ArrayList alColumnEffective = new ArrayList();
				alColumnEffective.Clear();

				dt_Book.Rows[0]["Mahang"] = strMahang; alColumnEffective.Add("Mahang");
				if (!StringUtils.IsEmpty(strTenHang))
				{
					dt_Book.Rows[0]["TenHang"] = strTenHang; alColumnEffective.Add("TenHang");
				}

				if (!StringUtils.IsEmpty(strQuantity))
				{
					dt_Book.Rows[0]["Quantity"] = strQuantity; alColumnEffective.Add("Quantity");
				}

				if (!StringUtils.IsEmpty(strUnit))
				{
					dt_Book.Rows[0]["Unit"] = strUnit; alColumnEffective.Add("Unit");
				}

				if (!StringUtils.IsEmpty(strPrice))
				{
					dt_Book.Rows[0]["Price"] = strPrice; alColumnEffective.Add("Price");
				}
				if (!StringUtils.IsEmpty(strCost))
				{
					dt_Book.Rows[0]["Cost"] = strCost; alColumnEffective.Add("Cost");
				}

				if (!StringUtils.IsEmpty(strNote))
				{
					dt_Book.Rows[0]["NOTE"] = strNote; alColumnEffective.Add("NOTE");
				}

				//Save
				_dbCarSv.SaveData("Water_HangHoa", dt_Book);

				#endregion

				#region // Return data

				DataSet dsGetData = new DataSet();
				dsGetData.Tables.Add(dt_Book.Copy());
				dsGetData.Tables[0].TableName = "Water_HangHoa";

				DataUtils.MoveDataTable(ref mdsFinal, ref dsGetData);

				#endregion

				// Return Good:
				TDALUtils.DBUtils.CommitSafety(_dbCarSv);
				mdsFinal.AcceptChanges();
				return mdsFinal;
			}
			catch (Exception exc)
			{
				#region // Catch of try:
				// Rollback:
				TDALUtils.DBUtils.RollbackSafety(_dbCarSv);
				// Return Bad:
				return TUtils.CProcessException.Process(
				ref mdsFinal
				, exc
				, strErrorCodeDefault
				, alParamsCoupleError.ToArray()
				);
				#endregion
			}
			finally
			{
				#region // Finally of try:
				// Rollback and Release resources:
				TDALUtils.DBUtils.RollbackSafety(_dbCarSv);
				TDALUtils.DBUtils.ReleaseAllSemaphore(_dbCarSv_Sys, true);
				TUtils.CProcessException.Process(
				ref mdsFinal // mdsFinal
				, _log // log
				, _strConfig_GwUserCode // strGwUserCodeForLog
				, _strConfig_GwUserPasswordForLog // strGwPasswordForLog
				, strFunctionName // strFunctionName
				, TUtils.CUtils.TidNext(strTid, ref nTidSeq) // strAppTid
				, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") // strAppTDateTime
				, strPartnerCode // strAppServiceCode
				, strPartnerUserCode // strAppUserCode
				, strLanguageCode // strLanguageCode
				, " // strRemark"
				);
				#endregion
			}
		}

		#endregion

		#region // Its_Water_HangHoa_Delete
		public DataSet Its_Water_HangHoa_Delete(
			string strGwUserCode
			, string strGwPassword
			, string strTid
			, string strPartnerCode
			, string strPartnerUserCode
			, string strLanguageCode
			, string strMahang
		)
		{
			#region // temp
			DataSet mdsFinal = CMyDataSet.NewMyDataSet(strTid);
			int nTidSeq = 0;
			bool bNeedTransaction = true;
			string strFunctionName = "Its_HangHoa_Delete";
			string strErrorCodeDefault = TError.ErrITS.Its_HangHoa_Delete;
			ArrayList alParamsCoupleError = new ArrayList(new object[]{
					"strFunctionName", strFunctionName
                   ,"strMahang",strMahang 
					});
			#endregion

			try
			{
				#region // Init:
				_dbCarSv.AppUserID = strPartnerUserCode;
				if (bNeedTransaction) _dbCarSv.BeginTransaction();

				// Write request log:
				_log.WriteLogAsync(
					_strConfig_GwUserCode // strGwUserCodeForLog
					, _strConfig_GwUserPasswordForLog // strGwPasswordForLog
					, strTid // strAppTid
					, strPartnerCode // strAppServiceCode
					, strPartnerUserCode // strAppUserCode
					, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") // strAppTDateTime
					, TError.Error.NoError // strAppErrorCode
					, strFunctionName // strAppLogType1
					, "REQUEST" // strAppLogType2
					, "" // strAppLogType3
					, strLanguageCode // strAppLanguageCode
					, "" // strAppRemark
					, TUtils.CUtils.ParamsCouple2ParamsTriple(alParamsCoupleError, 1, "").ToArray() // arrobjParamsTriple
					);

				// Check Valid Tid:
				myUtils_ValidateId(
					ref alParamsCoupleError // alParamsCoupleError
					, strTid // strTid
					, TError.ErrHTC.CommonInvalidTid // strErrCodeWhenInvalid
					);
				#endregion

				#region //HangHoa
				#region //Check
				DataTable dt_Book = null;
				this.CheckExistMaHang(
					 ref alParamsCoupleError
					, strMahang
					, out dt_Book
				 );

				#endregion

				#region // Save data
				string strSqlDelete = @"
						delete 
						from Water_HangHoa
						where
							Mahang = @strMahang
						;
					";

				// Save:
				myDebug_SaveSql(
					_bDebugMode // bDebugMode
					, ref alParamsCoupleError // alParamsCoupleError
					, string.Format("strSql_{0}", strFunctionName) // strParamName
					, strSqlDelete // strSql
					);
				_dbCarSv.ExecQuery(
					strSqlDelete
					, "@strMahang", strMahang
					);



				#endregion
				#endregion

				// Return Good:
				TDALUtils.DBUtils.CommitSafety(_dbCarSv);
				mdsFinal.AcceptChanges();
				return mdsFinal;
			}
			catch (Exception exc)
			{
				#region // Catch of try:
				// Rollback:
				TDALUtils.DBUtils.RollbackSafety(_dbCarSv);

				// Return Bad:
				return TUtils.CProcessException.Process(
					ref mdsFinal
					, exc
					, strErrorCodeDefault
					, alParamsCoupleError.ToArray()
					);
				#endregion
			}
			finally
			{
				#region // Finally of try:
				// Rollback and Release resources:
				TDALUtils.DBUtils.RollbackSafety(_dbCarSv);
				TDALUtils.DBUtils.ReleaseAllSemaphore(_dbCarSv_Sys, true);

				TUtils.CProcessException.Process(
					ref mdsFinal // mdsFinal
					, _log // log
					, _strConfig_GwUserCode // strGwUserCodeForLog
					, _strConfig_GwUserPasswordForLog // strGwPasswordForLog
					, strFunctionName // strFunctionName
					, TUtils.CUtils.TidNext(strTid, ref nTidSeq) // strAppTid
					, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") // strAppTDateTime
					, strPartnerCode // strAppServiceCode
					, strPartnerUserCode // strAppUserCode
					, strLanguageCode // strLanguageCode
					, "" // strRemark
					);
				#endregion
			}
		}
		#endregion

		#endregion
    }
}
